package frame;

import Homework.Commodity;
import Homework.IUse;
import Homework.UseImp;
import com.lovo.netCRM.component.LovoButton;
import com.lovo.netCRM.component.LovoTxt;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class AddFrame extends JFrame {
    private LovoTxt numTxt = new LovoTxt("编号", 50, 30, this);
    private LovoTxt nameTxt = new LovoTxt("商品名", 50, 60, this);
    private LovoTxt priceTxt = new LovoTxt("单价", 50, 90, this);
    private LovoTxt factoryTxt = new LovoTxt("厂家", 50, 120, this);
    private LovoTxt productDateTxt = new LovoTxt("生产日期", 50, 150, this);

    private IUse use = new UseImp();


    public AddFrame(){
        this.setLayout(null);

        this.init();

        this.setSize(400,300);
        this.setVisible(true);
        this.setDefaultCloseOperation(3);
        this.setLocationRelativeTo(null);
    }

    private void init(){
        LovoButton addButton = new LovoButton("添加",150,200,this);
        addButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                addCommodity();
            }
        });

    }

    private void addCommodity(){
        //数据验证

        //数据添加
        use.add(new Commodity(Integer.parseInt(numTxt.getText()),nameTxt.getText(),priceTxt.getText(),
                factoryTxt.getText(),productDateTxt.getText()));
        this.dispose();
        new MainFrame();
    }


}
